package org.veridiandynamics.client.view;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

/**
 * @author Talia
 * 
 * This represents the panel displayed inside the program when a patient logs in to the system.
 *
 */
public class ViewPatientPanel extends JPanel {

	private CardLayout c1;
	private JPanel basePanel;

	
	/**
	 * Constructor for panel
	 * 
	 * @param c1 The cardlayout being used
	 * @param basePanel The base panel for this JPanel
	 */
	public ViewPatientPanel(final CardLayout c1, final JPanel basePanel)
	{
		this.c1 = c1;
		this.basePanel = basePanel;
		setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(47dlu;default)"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(27dlu;default):grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblViewPatientsHere = new JLabel("View patients here:");
		add(lblViewPatientsHere, "4, 4");
		
		JTextArea textArea = new JTextArea();
		add(textArea, "6, 6, fill, fill");
		
		Map<String, Object> viewPatients = new HashMap<String, Object>();
		viewPatients.put("requestType", "viewPatients");
		
//		for(Patient p: patientList)
//		{
//			try {
//				textArea.append("Patient: " + "\n" + p.toString() + "\n"); 
//			}
//			catch(NullPointerException e)
//			{
//				JOptionPane.showMessageDialog(null, "Alert! Some patients stored " + 
//						"in the database do not have first or last names");
//			}
//		}
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				c1.first(basePanel);
			}
		});
		add(btnBack, "8, 8");
	}

}
